#!/bin/bash

# 更新系统
echo "Updating the system..."
sudo yum update -y

# 安装EPEL仓库
echo "Installing EPEL repository..."
sudo yum install epel-release -y

# 安装Redis
echo "Installing Redis..."
sudo yum install redis -y

# 配置Redis
echo "Configuring Redis..."
sudo sed -i 's/^bind 127.0.0.1/bind 0.0.0.0/' /etc/redis.conf
#sudo sed -i 's/# requirepass foobared/requirepass your_password/' /etc/redis.conf

# 启动Redis服务
echo "Starting Redis service..."
sudo systemctl start redis

# 设置Redis开机自启
echo "Enabling Redis to start on boot..."
sudo systemctl enable redis

# 检查Redis状态
echo "Checking Redis status..."
sudo systemctl status redis

# 测试Redis
echo "Testing Redis..."
redis-cli  ping
#redis-cli -a your_password ping

# 配置防火墙
echo "Configuring firewall for Redis..."
sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
sudo firewall-cmd --reload

# 完成安装
echo "Redis installation completed."